#ifndef _arithmetic_hpp
#define _arithmetic_hpp

using uint = unsigned int;

uint hex_to_dec(char ch)
{
    if (ch == 'A') return 10;
    if (ch == 'B') return 11;
    if (ch == 'C') return 12;
    if (ch == 'D') return 13;
    if (ch == 'E') return 14;
    if (ch == 'F') return 15;
    return ch - '0';
}

uint sext(uint x, int len)
{
    if (x & (1 << len))
        x += ~((1 << (len + 1)) - 1);
    return x;
}

#endif